Adding Parameters to an Apple Event
Adding Parameters to an Apple Event
You can use the AEPutParamPtr or AEPutParamDesc function to add
parameters to an Apple event. When you use either of these functions, the
Apple Event Manager adds the specified parameter to the Apple event.
Use the AEPutParamPtr function when you want to add data specified in a
buffer as the parameter of an Apple event. You specify the Apple event, the
keyword of the parameter to add, the descriptor type, a buffer that contains the
data, and the size of this buffer as parameters to the AEPutParamPtr
function. The AEPutParamPtr function creates the descriptor record and
adds the parameter to the Apple event.
For example, this code adds a parameter to the Multiply event using the
AEPutParamPtr function.
# define keyOperand1 'OPN1'
long number1;
AppleEvent theAppleEvent;
OSErr myErr;
number1 = 10;
myErr = AEPutParamPtr(& theAppleEvent, keyOperand1,
typeLongInteger,& number1, sizeof( number1));
In this example, the Apple Event Manager adds the parameter containing
the first number to the specified Apple event.
Use the AEPutParamDesc function to add data specified in a
descriptor record to an Apple event. The descriptor record you specify must
have been previously created using the AECreateDesc or AEDuplicateDesc
function.
You specify the descriptor type, a buffer that contains the data, and the size of
this buffer as parameters to the AECreateDesc function. The AECreateDesc
function returns the descriptor record that describes the data.
This example creates a descriptor record for the second parameter of the
Multiply event:
long number2;
AEDesc multParam2Desc
OSErr myErr;
number2 = 8;
myErr = AECreateDesc( typeLongInteger, & number2, sizeof( number2),
&multParam2Desc);
In this example, the AECreateDesc function creates a descriptor record
with the typeLongInteger descriptor type and the data identified in the number2
variable.
Once you have created a descriptor record, you can use AEPutParamDesc to
add the data to a parameter of an Apple event. You specify the Apple event to add
the parameter to, the keyword of the parameter, and the
descriptor record of the parameter as parameters to the AEPutParamDesc
function.
This example adds a second parameter to the Multiply event using the
AEPutParamDesc function.
#define keyOperand2 'OPN2'
myErr = AEPutParamDesc(& theAppleEvent,
keyOperand2,&multParam2Desc);
This example adds the keyOperand2 keyword and the descriptor record
created in the previous example as the second parameter to the specified Apple
event.
The previous examples showed how to add parameters to the imaginary
Multiply event. After adding parameters to an Apple event, you can send the
Apple event using the AESend function.